package coms.ejb.sessionbean;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import coms.datatransfer.UserDTO;
import coms.dataaccess.DAOFactory;
import coms.dataaccess.ReviewDao;
import coms.dataaccess.UserDao;
import coms.dataaccess.hibernate.UserDaoImpl;

/**
 * Session Bean implementation class UserBean
 */
@Stateless(name = "UserBean", mappedName = "UserBeanMapName")
@Remote(UserBeanRemote.class)

public class UserBean implements UserBeanRemote {

    /**
     * Default constructor. 
     * 
     * 
     */
	
	private UserDao ud = null;
	
    public UserBean() {}

    public void ejbCreate() {
    	ud = DAOFactory.getInstance().getUserDAO();
    }
    
	@Override
	public UserDTO validateUser(UserDTO usr) {
		
		//System.out.println("Hi Service");
		//System.out.println(usr.getRoleID());
		//System.out.println(ud.getUserByID(usr.getRoleID()).getUserID());
		
		
		/*if(ud.getUserByID(usr.getUserID()).getUserID()==usr.getUserID() && ud.getUserByID(usr.getRoleID()).getPassword().equalsIgnoreCase(usr.getPassword())){
			return 1;		
		}else
			return 0;*/
	
		return ud.validateUser(usr);
	
	}  

	@Override
	public void createUser(UserDTO usr) {
		// TODO Auto-generated method stub
		ud.createUser(usr);
		
		System.out.println("In Session User");
	}
	
	public List<UserDTO> findUserByRoleID(int roleID) {
		
		List<UserDTO> reviewersList = new ArrayList<UserDTO>();
		List<Object[]> reviewUserList = ud.findUserByRoleID(roleID);
		for(Object[] a: reviewUserList)
			reviewersList.add((UserDTO)a[0]);
		return reviewersList;
	}

}
